Repository navigation
Conversation
Documentation build overview
88 files changed ·
|
| :func:`socket.getfqdn`. If the :meth:`connect` call returns anything other | ||
| :func:`socket.getfqdn`. If it is not fully qualified, the connected socket's | ||
| local IP address is used as an address literal instead. IPv6 addresses use | ||
| the ``[IPv6:address]`` form. If the :meth:`connect` call returns anything other |
There was a problem hiding this comment.
I'm not sure it is useful to call out IPv6 separately here, since what we are doing is (now) following the standard, but I don't have a strong objection to including it.
There was a problem hiding this comment.
Updated the parameter documentation to describe the socket local address literal without singling IPv6 out.
| ) | ||
| for family, address, expected in cases: | ||
| for connect_in_init in (True, False): | ||
| with self.subTest(family=family, connect_in_init=connect_in_init): |
There was a problem hiding this comment.
I think it would be good to include address in the subtest description.
There was a problem hiding this comment.
Added the address to the subTest description.
| except socket.gaierror: | ||
| pass | ||
| self.local_hostname = '[%s]' % addr | ||
|
|
There was a problem hiding this comment.
As far as I can see, the second part of this inner else is now code that doesn't have any effect, since local_hostname then gets reset unconditionally in connect. I suggest the following:
self.local_hostname = local_hostname
if local_hostname is None:
# RFC 2821 says we should use the fqdn in the EHLO/HELO verb, and
# if that can't be calculated, that we should use a domain literal
# instead (essentially an encoded IP address like [A.B.C.D]).
fqdn = socket.getfqdn()
if '.' in fqdn:
self.local_hostname = fqdn
else:
# We can't find an fqdn hostname, so we'll compute the
# correct domain literal in connect.
self._find_local_hostname = True
And then of course changing _use_socket_hostname to _find_local_hostname in connect. What do you think? The tests, including the new ones, still pass.
There was a problem hiding this comment.
Changed the flag to _find_local_hostname and now defer hostname fallback address selection to connect, following your suggested flow.
| if code == 220 and self._use_socket_hostname: | ||
| addr = self.sock.getsockname()[0] | ||
| if self.sock.family == socket.AF_INET6: | ||
| # An SMTP address literal does not include a scope identifier. |
There was a problem hiding this comment.
For clarity, let's add: but does require an IPv6 "tag" per RFC 5321 Section 4.1.3
There was a problem hiding this comment.
Updated the comment to cite RFC 5321 section 4.1.3 and explain the IPv6 tag and scope-ID handling.
| if self.sock.family == socket.AF_INET6: | ||
| # An SMTP address literal does not include a scope identifier. | ||
| addr = 'IPv6:' + addr.split('%', 1)[0] | ||
| self.local_hostname = '[%s]' % addr |
There was a problem hiding this comment.
I think it would be clearer to use an f-string here.
There was a problem hiding this comment.
Changed the IPv6 literal construction to an f-string.
| @@ -0,0 +1,3 @@ | |||
| When no fully qualified hostname is available, :mod:`smtplib` now uses the | |||
| connected socket's local address for the HELO/EHLO address literal, including | |||
| properly formatted IPv6 literals. | |||
There was a problem hiding this comment.
I'd add: "Previously IPv6 was not handled correctly."
There was a problem hiding this comment.
Updated the news entry to note that IPv6 was previously not handled correctly.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
a58dc50 to
93d6c56
Compare
|
I pushed the requested code and documentation updates in 93d6c56 and replied to each inline review comment. The focused |
Uh oh!
There was an error while loading. Please reload this page.